/**
 * Copyright © 2012, 2013 dr. ir. Jeroen M. Valk
 * 
 * This file is part of ComPosiX.
 * 
 * ComPosiX is free software: you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * 
 * ComPosiX is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * ComPosiX. If not, see <http://www.gnu.org/licenses/>.
 */

Ext.require('Ext.button.*');
Ext.onReady(function() {
	var win = null;
	var winSource = null;

	var store = Ext.create('Ext.data.TreeStore', {
		root : {
			expanded : true,
			children : [ {
				text : "RootLayer",
				expanded : true,
				children : [ {
					text : 'Root: root',
					leaf : true
				} ]
			}, {
				text : "Layer1",
				expanded : true,
				children : [ {
					text : "Edge: left",
					leaf : true
				}, {
					text : "Edge: right",
					leaf : true
				} ]
			}, {
				text : "Layer2",
				expanded : true,
				children : [ {
					text : 'Edge: left',
					leaf : true
				}, {
					text : 'Internal: center',
					leaf : true
				}, {
					text : 'Edge: right',
					leaf : true
				} ]
			}, {
				text : "Layer3",
				expanded : true,
				children : [ {
					text : 'Edge: left',
					leaf : true
				}, {
					text : 'Internal: left',
					leaf : true
				}, {
					text : 'Internal: right',
					leaf : true
				}, {
					text : 'Edge: right',
					leaf : true
				} ]
			}, {
				text : 'Layer4',
				expanded : true,
				children : [ {
					text : 'Edge: left',
					leaf : true
				}, {
					text : 'Internal: left',
					leaf : true
				}, {
					text : 'Internal: center',
					leaf : true
				}, {
					text : 'Internal: right',
					leaf : true
				}, {
					text : 'Edge: right',
					leaf : true
				} ]
			} ]
		}
	});

	var panel = Ext.create('Ext.tree.Panel', {
		title : 'Pascal\'s Triangle',
		width : 200,
		height : 150,
		tbar : [ {
			xtype : 'button',
			text : 'source',
			handler : function() {
				if (!winSource) {
					winSource = Ext.create('Ext.Window', {
						title : 'Source',
						width : 400,
						height : 200,
						x : 450,
						y : 200,
						headerPosition : 'top',
						layout : 'fit'
					});
				}
				if (winSource.isVisible()) {
					winSource.hide(this, function() {
					});
				} else {
					winSource.show(this, function() {
					});
				}

			}
		} ],
		store : store,
		rootVisible : false,
		collapsible : true,
		resizable : true,
		titleCollapse : true
	});

	panel.addListener('itemclick', function(aaa, bbb, ccc, ddd) {
		if (winSource) {

		}
	});

	var button = Ext.create('Ext.Button', {
		text : null,
		scale : 'large',
		icon : 'images/dataflow-large.png',
		renderTo : 'CPX',
		handler : function() {
			if (!win) {
				win = Ext.create('Ext.Window', {
					title : 'ComPosiX',
					width : 400,
					height : 200,
					x : 450,
					y : 200,
					headerPosition : 'right',
					layout : 'fit',
					items : panel
				});
			}
			if (win.isVisible()) {
				win.hide(this, function() {
				});
			} else {
				win.show(this, function() {
				});
			}

		}
	});

});
